/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-8-30 下午4:04 Created by dwzhang
 */
package com.jade.modules.message.service.pipeline;

import com.jade.framework.base.pattern.pipeline.Valve;
import com.jade.framework.base.pattern.pipeline.ValveChain;
import com.jade.modules.message.service.InterruptMessageException;
import com.jade.modules.message.service.MessageException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 抽象的处理阀门。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-8-30 下午4:04
 */
public abstract class AbstractMessageValve
        extends Valve<MessageContext, MessageException>
{
    protected Log log = LogFactory.getLog(this.getClass());

    public void handle(MessageContext messageContext,
                       ValveChain<MessageContext, MessageException> chain)
            throws MessageException
    {
        try {
            doHandle(messageContext);
            chain.handleNext(messageContext);
        }
        catch (InterruptMessageException e) {
            log.warn("Application interrupt message:" + e.getMessage());
        }
    }

    protected abstract void doHandle(MessageContext context)
            throws MessageException;
}
